package com.xbx.zuul.filter;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * 自定义登陆过滤拦截器
 *
 * @author 89005691
 * @create 2018-10-15 15:48
 */
@Slf4j
public class MyFormAuthenticationFilter extends FormAuthenticationFilter {

    @Override
    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {

        HttpServletRequest httpServletRequest = (HttpServletRequest) request;

        // 如果是option请求，直接放行
        if ("OPTIONS".equalsIgnoreCase(httpServletRequest.getMethod())) {

            log.info("OPTIONS请求通行，请求路径{}", httpServletRequest.getRequestURI());
            return true;
        }

        return super.onAccessDenied(request, response);
    }
}
